<?php
namespace core;

use interfaces\Provider;
/**
 * 实现容器的基本数组方法
 */
class Container implements \ArrayAccess 
{

    // 容器内所有实例
    protected $instances = [];

    // 容器内所有绑定的类名
    protected $bind = [];

    // 注册提供者
    public function providerRegister(Provider $provider)
    {
        return $provider->serviceProvider($this);
    }

	public function offsetExists($offset) 
    {
        return "exists";
    }

    public function offsetGet($offset)
    {
        if (isset($this->instances[$offset])) {
            return $this->instances[$offset];
        }

        $row = $this->bind[$offset];
        $obj = $this->instances[$offset] = $row();

        return $obj;
    }

    public function offsetSet($offset, $value)
    {
        $this->bind[$offset] = $value;
        return $this;
    }

    public function offsetUnset($offset)
    {
        
    }

}

?>